import { defineConfig } from 'vite';
import { metablock } from 'vite-plugin-userscript';
// import typescript from '@vitejs/plugin-typescript';

export default defineConfig({
  build: {
    target: 'esnext',
    lib: {
      entry: 'src/main.ts',
      name: 'MyTampermonkeyScript',
      formats: ['iife'],
      fileName: 'bundle.vite'
    },
    watch: {
      exclude: 'node_modules/**',
      buildDelay: 1e3,
    },
    rollupOptions: {
      treeshake: 'smallest'
    },
    terserOptions: {
      compress: {
        unused: true,       // 删除未使用的变量
        drop_console: true  // 移除所有 console.log
      }
    },
    commonjsOptions: {},
    dynamicImportVarsOptions: {}
  },

  plugins: [
    // typescript()
    metablock({
      headers: {
        name: 'My Script',
        match: 'https://example.com/*'
      }
    }),
  ]
});